package com.atguigu.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

//@Component
//@Aspect
public class TxAroundAdvice {
    /*
    * 环绕通知，需要你在通知中，定义目标方法的执行
    * @param joinPoint 目标方法(获取目标方法信息，多了一个执行方法)
    * @return 目标方法的返回值
    * */
    @Around("com.atguigu.pointcut.MyPointCut.pc()")
    public Object transaction(ProceedingJoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        Object result = null;
        try {
            System.out.println("开启事务");
            result = joinPoint.proceed(args);
            System.out.println("结束事务");
        } catch (Throwable throwable) {
            System.out.println("事务回滚");
            throwable.printStackTrace();
        }finally {

        }
        return result;
    }
}
